package com.example.banksys;

import DataBase.DBMsg;
import DataBase.myDB;
import com.pixelduke.control.skin.FXSkins;
import handler.queryHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.stage.Window;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AccountLoginController {
    public PasswordField passwd;
    public Button confirm;

    public Account currAcc;

    public AnchorPane pane;

    public long account_ID;

    public void initialize(){
        this.currAcc=new Account();    }

    public void confirm() throws SQLException, IOException {
        if(passwd.getText().equals("")||passwd.getText().isEmpty()){
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.titleProperty().set("信息");
            alert.headerTextProperty().set("请输入正确密码！");
            alert.showAndWait();
        }else{
            currAcc.setAccount_ID(account_ID);
            currAcc.setPassword(passwd.getText());
            queryHandler loghandler=new queryHandler();
            DBMsg t=loghandler.accountQuery(currAcc);
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.titleProperty().set("信息");
            alert.headerTextProperty().set(t.getInfo());
            alert.showAndWait();
            if(t.getState()== DBMsg.State.SUCCESS){
                Stage currstage=(Stage)pane.getScene().getWindow();
                FXMLLoader fxmlLoader=new FXMLLoader(MainApplication.class.getResource("accountOperate.fxml"));
                AccountOperateController accountoperatecontroller=fxmlLoader.getController();
                //accountoperatecontroller.account_ID=this.currAcc.getAccount_ID();
                currstage.setScene(new Scene(fxmlLoader.load()));
            }
        }

    }


}
